home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / xtra.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  6KB  |  278 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "paintop.h"
  13. #include "font.h"
  14.  
  15. #define    CTRL_H    8
  16. #define    NL    10
  17. #define    CR    13
  18. #define    CTRL_U    21
  19. #define    CTRL_X    24
  20. #define    DEL    127
  21.  
  22. #ifdef AMIGA
  23. #else
  24. PR_SIZE pf_textwidth(n, f, s)
  25.     int        n;
  26.     XFontStruct    *f;
  27.     char        *s;
  28. {
  29.     int        dummy;
  30.     XCharStruct    ch;
  31.     PR_SIZE        ret;
  32.  
  33.     XTextExtents(f, s, n, &dummy, &dummy, &dummy, &ch);
  34.     ret.x = ch.width;
  35.     ret.y = ch.ascent + ch.descent;
  36.     return (ret);
  37. }
  38.  
  39. static GC makegc(op, fg, bg)
  40. int    op;
  41. Pixel    fg;
  42. Pixel    bg;
  43. {
  44.     register GC    ngc;
  45.     XGCValues    gcv;
  46.     int        gcmask;
  47.  
  48.     gcv.font = roman_font->fid;
  49.     gcmask = GCFunction|GCForeground|GCBackground|GCFont;
  50.     switch (op) {
  51.     case PAINT:
  52.         gcv.foreground = fg;
  53.         gcv.background = bg;
  54.         gcv.function = GXcopy;
  55.         break;
  56.     case ERASE:
  57.         gcv.foreground = bg;
  58.         gcv.background = bg;
  59.         gcv.function = GXcopy;
  60.         break;
  61.     case INV_PAINT:
  62.         gcv.foreground = fg ^ bg;
  63.         gcv.background = bg;
  64.         gcv.function = GXxor;
  65.         break;
  66.     case MERGE:
  67.         gcv.foreground = fg;
  68.         gcv.background = bg;
  69.         gcv.function = GXor;
  70.         break;
  71.     }
  72.     
  73.     ngc = XCreateGC(tool_d, XtWindow(canvas_sw), gcmask, &gcv);
  74.     XCopyGC(tool_d, gc, ~(gcmask), ngc);
  75.     return (ngc);
  76. }
  77.  
  78. static GC    msg_gccache[0x10];
  79.  
  80. init_gc()
  81. {
  82.     Pixel    bg, fg;
  83.     Arg    tmp_arg[2];
  84.     
  85.     gccache[PAINT] = makegc(PAINT, x_fg_color.pixel, x_bg_color.pixel);
  86.     gccache[ERASE] = makegc(ERASE, x_fg_color.pixel, x_bg_color.pixel);
  87.     gccache[INV_PAINT] = makegc(INV_PAINT, x_fg_color.pixel,
  88.                     x_bg_color.pixel);
  89.     gccache[MERGE] = makegc(MERGE, x_fg_color.pixel, x_bg_color.pixel);
  90.  
  91.     /* Need to get the values so we can make GC's which XOR correctly */
  92.     XtSetArg(tmp_arg[0], XtNforeground, &fg);
  93.     XtSetArg(tmp_arg[1], XtNbackground, &bg);
  94.     XtGetValues(msg_sw, tmp_arg, 2);
  95.  
  96.     msg_gccache[PAINT] = makegc(PAINT, fg, bg);
  97.     msg_gccache[ERASE] = makegc(ERASE, fg, bg);
  98.     
  99.     XtSetArg(tmp_arg[0], XtNforeground, &fg);
  100.     XtSetArg(tmp_arg[1], XtNbackground, &bg);
  101.     XtGetValues(topruler_sw, tmp_arg, 2);
  102.  
  103.     topgc = makegc(INV_PAINT, fg, bg);
  104.     
  105.     XtSetArg(tmp_arg[0], XtNforeground, &fg);
  106.     XtSetArg(tmp_arg[1], XtNbackground, &bg);
  107.     XtGetValues(sideruler_sw, tmp_arg, 2);
  108.     
  109.     sidegc = makegc(INV_PAINT, fg, bg);
  110. }
  111.  
  112. /*
  113. **    The next routine is easy to implement, but I haven't missed
  114. **    it yet. Generally it is a bad idea to warp the mouse without
  115. **    the users consent, so maybe the original code is wrong?
  116. */
  117. win_setmouseposition(w,x,y)
  118.     FDTYPE        w;
  119.     int        x, y;
  120. {
  121. }
  122.  
  123. int wmgr_confirm(w, message)
  124.     Window        w;
  125.     char        *message;
  126. {
  127.     static TOOL    label = NULL, confirm = NULL;
  128.     XEvent        event;
  129.     Arg    tmp_args[2];
  130.  
  131.     if( confirm == NULL )
  132.     {
  133.         Position    rootx, rooty;
  134.         Window        win;
  135.         Arg        confirm_args[5];
  136.         
  137.         XTranslateCoordinates(tool_d, w, XDefaultRootWindow(tool_d),
  138.                       150, 200, &rootx, &rooty, &win);
  139.         XtSetArg(confirm_args[0], XtNallowShellResize, True);
  140.         XtSetArg(confirm_args[1], XtNx, rootx);
  141.         XtSetArg(confirm_args[2], XtNy, rooty);
  142.         confirm = XtCreatePopupShell("confirm",
  143.                          overrideShellWidgetClass, tool,
  144.                          confirm_args, 3);
  145.         XtSetArg(tmp_args[0], XtNfont, bold_font);
  146.         label = XtCreateManagedWidget("label", labelWidgetClass,
  147.                           confirm, tmp_args, 1);
  148.     }
  149.     
  150.     XtSetArg(tmp_args[0], XtNlabel, message);
  151.     XtSetValues(label, tmp_args, 1);
  152.     XtPopup(confirm, XtGrabNone);
  153.     for (;;)
  154.     {
  155.         XMaskEvent(tool_d, ButtonPressMask|ExposureMask, &event);
  156.         if (event.type == ButtonPress)
  157.         {
  158.             XtPopdown(confirm);
  159.             if (((XButtonEvent *)&event)->button == Button1)
  160.                 return (-1);
  161.             else
  162.                 return (0);
  163.         }
  164.         /* pass all other events */
  165.         XtDispatchEvent(&event);
  166.     }
  167. /*NOTREACHED*/
  168. }
  169.  
  170. prompt_string(prompt, reply)
  171.     char        *prompt, *reply;
  172. {
  173.     register int    x, y;
  174.     register int    len, width;
  175.     register char    *r = reply;
  176.     XEvent        event;
  177.     register XKeyEvent    *ke = (XKeyEvent *)&event;
  178.     char        buf[1];
  179.     XWindowAttributes    attr;
  180.  
  181.     XClearArea(tool_d, msgswfd, 0, 0, 0, 0, False);
  182.     /* uses knowledge that msg_gccache[PAINT] uses roman_font - tsk */
  183.     len = strlen(prompt);
  184.     width = char_width(roman_font);
  185.     y = char_height(roman_font) + 2;
  186.     XDrawString(tool_d, msgswfd, msg_gccache[PAINT], 2, y, prompt, len);
  187.     x = width * len + 4;
  188.     XGetWindowAttributes(tool_d, msgswfd, &attr);
  189.     XSelectInput(tool_d, msgswfd, attr.your_event_mask | KeyPressMask);
  190.     for (;;)
  191.     {
  192.         XWindowEvent(tool_d, msgswfd, KeyPressMask, &event);
  193.         if (event.type != KeyPress)
  194.             continue;
  195.         if (XLookupString(ke, buf, sizeof(buf), NULL, NULL) <= 0)
  196.             continue;
  197.         switch (buf[0])
  198.         {
  199.         case CTRL_H:
  200.         case DEL:
  201.             if (r != reply)
  202.             {
  203.                 x -= width;
  204.                 --r;
  205.                 XDrawString(tool_d, msgswfd, msg_gccache[ERASE],
  206.                     x, y, r, 1);
  207.             }
  208.             break;
  209.         case CTRL_U:
  210.         case CTRL_X:
  211.             while (r != reply)
  212.             {
  213.                 x -= width;
  214.                 --r;
  215.                 XDrawString(tool_d, msgswfd, msg_gccache[ERASE],
  216.                     x, y, r, 1);
  217.             }
  218.             break;
  219.         case CR:
  220.         case NL:
  221.             *r = '\0';
  222.             XClearArea(tool_d, msgswfd, 0, 0, 0, 0, False);
  223.             return;
  224.         default:
  225.             if (buf[0] < ' ' || buf[0] > '~')
  226.                 continue;
  227.             XDrawString(tool_d, msgswfd, msg_gccache[PAINT],
  228.                 x, y, buf, 1);
  229.             x += width;
  230.             *r++ = buf[0];
  231.             break;
  232.         }
  233.     }
  234. }
  235.  
  236. static void
  237. CvtStringToFloat(args, num_args, fromVal, toVal)
  238. XrmValuePtr    args;
  239. Cardinal    *num_args;
  240. XrmValuePtr    fromVal;
  241. XrmValuePtr    toVal;
  242. {
  243.     static    float    f;
  244.  
  245.     if(*num_args != 0 )
  246.         XtWarning("String to Float conversion needs no extra arguments");
  247.     if(sscanf((char *)fromVal->addr, "%f", &f) == 1)
  248.     {
  249.         (*toVal).size = sizeof(float);
  250.         (*toVal).addr = (caddr_t) &f;
  251.     }
  252.     else
  253.         XtStringConversionWarning((char *) fromVal->addr, "Float");
  254. }
  255.  
  256. static void
  257. CvtIntToFloat(args, num_args, fromVal, toVal)
  258. XrmValuePtr    args;
  259. Cardinal    *num_args;
  260. XrmValuePtr    fromVal;
  261. XrmValuePtr    toVal;
  262. {
  263.     static    float    f;
  264.  
  265.     if(*num_args != 0 )
  266.         XtWarning("Int to Float conversion needs no extra arguments");
  267.     f = *(int *)fromVal->addr;
  268.     (*toVal).size = sizeof(float);
  269.     (*toVal).addr = (caddr_t) &f;
  270. }
  271.  
  272. fix_converters()
  273. {
  274.     XtAddConverter("String", "Float", CvtStringToFloat, NULL, 0);
  275.     XtAddConverter("Int", "Float", CvtIntToFloat, NULL, 0);
  276. }
  277. #endif
  278.